<template>
	<view class="mainpadding">
		<view class="xiaohei fonweight titletext">我的积分：
			<text class="xiaohong fonweight sanshier" style="font-size: 40rpx;">{{userInfo.score}}</text>
		</view>
		<view class="flexleft margin_top">
			<view class="xiaohei fonweight  titletext" style="min-width: 160rpx;">赠送人：</view>
			<input class="input" style="width: 100%;" type="number" placeholder="被赠送人手机号" v-model="mobile">
		</view>
		<view class="flexleft margin_top">
			<view class="xiaohei fonweight  titletext" style="min-width: 160rpx;">赠送积分：</view>
			<input class="input" style="width: 100%;" type="number" placeholder="赠送积分" v-model="score">
		</view>


		<view class="mainpadding2 gudingdb">
			<view class="bigbtn" @click="submit">赠送</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")

	export default {
		data() {
			return {
				mobile: "",
				score: "",
				userInfo: {}
			}
		},
		onShow() {
			this.userinfo()
		},
		methods: {
			submit() {
				if(this.score==""){
					httpRequest.toast("请输入赠送积分")
					return false
				}
				if (Number(this.userInfo.score) < Number(this.score)) {
					httpRequest.toast("赠送积分不能大于当前剩余积分")
					return false
				}
				if(this.mobile==""){
					httpRequest.toast("请输入被赠送人手机号")
					return false
				}
				httpRequest.request('/api/user/sendUserScore', 'GET', {
					mobile:this.mobile,
					score:this.score
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				})
			},
			userinfo() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.userInfo = res.data
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.input {
		border-radius: 20rpx;
		padding: 20rpx 30rpx;
		background-color: #fff;
	}
</style>